package com.itheima.controller;

import com.itheima.domain.OmsOrderReturnReason;
import com.itheima.manager.OmsOrderReturnReasonManager;
import com.itheima.util.R;
import com.itheima.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class OmsOrderReturnReasonController {

    @Autowired
    private OmsOrderReturnReasonManager omsOrderReturnReasonManager;

    @GetMapping("/returnReason/list")
    public R getPage(
            @RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){
        PageBeanVo pageBeanVo =  omsOrderReturnReasonManager.getPage(pageNum,pageSize);
        return R.success(pageBeanVo);
    }
    // 添加一条
    @PostMapping("/returnReason/create")
    public R save(@RequestBody OmsOrderReturnReason omsOrderReturnReason){
        return omsOrderReturnReasonManager.save(omsOrderReturnReason);

    }

    // 删除批量
    @PostMapping("/returnReason/delete")
    public R delete(@RequestParam("ids")List<Long> ids){
        omsOrderReturnReasonManager.delete(ids);
        return R.success(null);
    }
    // 修改状态 是否可以使用
    @PostMapping("/returnReason/update/status")
    public R updateStatus(@RequestParam("ids") List<Long> ids,Integer status){
        omsOrderReturnReasonManager.updateStatus(ids,status);
        return R.success(null);
    }
    // 数据回显
    @GetMapping("/returnReason/{id}")
    public R findById(@PathVariable Long id){
       OmsOrderReturnReason omsOrderReturnReason= omsOrderReturnReasonManager.findById(id);
       return R.success(omsOrderReturnReason);
    }
    @PostMapping("/returnReason/update/{id}")
    public R update(@PathVariable Long id,
                    @RequestBody OmsOrderReturnReason omsOrderReturnReason){
        omsOrderReturnReasonManager.update(id,omsOrderReturnReason);
        return R.success(null);
    }
}
